package utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletContext;

import com.mysql.jdbc.PreparedStatement;

public class CMUser {
	
	String mFirstName;
	String mLastName;
	String mPhoneNumber;
	
	
	
	
	public CMUser(ServletContext context, String username) throws ClassNotFoundException, SQLException {
		DBConnector dbConn = null;
		try {
			dbConn = new DBConnector();
	
			PreparedStatement stmnt = (PreparedStatement) dbConn.getConnection().prepareStatement(
			"SELECT * FROM users WHERE username = ? ");
			
			stmnt.setString(1, username);
			ResultSet res = stmnt.executeQuery();
			
			if (!res.next()) {
				throw new SQLException();
			}
			
			mFirstName = res.getString("first_name");
			mLastName = res.getString("last_name");
			mPhoneNumber = res.getString("phone_number");
		}
		finally {
			try {
				dbConn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
			
	}




	
	public String getFirstName() {
		return mFirstName;
	}




	public String getLastName() {
		return mLastName;
	}




	public String getPhoneNumber() {
		return mPhoneNumber;
	}
	
	


}

